(function userManagerOperation(){
	function selectAll(){
		let all=document.querySelector("#all");
		let checks=document.getElementsByName("id_check");
		for(let i=0,len=checks.length;i<len;i++){
			if(all.checked==true){
				checks[i].checked=true;
			}else{
				checks[i].checked=false;
			}
		}
	}
	function deleteUser(){
		let checks=document.getElementsByName("id_check");
		let param="";
		for(let i=0,len=checks.length;i<len;i++){
			if(checks[i].checked==true){
				if(param==""){
					param+=checks[i].id;
				}else{
					param+=",";
					param+=checks[i].id;
				}
			}
		}
		if(param==""){
			alert("请选择要删除的数据！");
		}else{
			window.location.href="user.servlet?param=doDelete&ids="+param;
		}
	}
	function updateRole(){
		let checks=document.getElementsByName("id_check");
		let param="";
		let count=0;
		for(let i=0,len=checks.length;i<len;i++){
			if(checks[i].checked==true){
				param+=checks[i].id;
				count++;
			}
		}
		if(count==0){
			alert("请选择要修改的数据！");
		}else if(count>1){
			alert("一次只能修改一行数据");
		}else if(count==1){
			window.location.href="userRole.servlet?param=update&id="+param;
		}		
	}
	function updateUser(){
		let checks=document.getElementsByName("id_check");
		let param="";
		let count=0;
		for(let i=0,len=checks.length;i<len;i++){
			if(checks[i].checked==true){
				param+=checks[i].id;
				count++;
			}
		}
		if(count==0){
			alert("请选择要修改的数据！");
		}else if(count>1){
			alert("一次只能修改一行数据");
		}else if(count==1){
			window.location.href="user.servlet?param=update&id="+param;
		}
	}
	function init(){
		document.querySelector("#btn_addUser").addEventListener("click",()=>{
			window.location.href="user.servlet?param=add";
		},false);
		document.querySelector("#btn_updateUser").addEventListener("click",updateUser,false);
		document.querySelector("#btn_deleteUser").addEventListener("click",deleteUser,false);
		document.querySelector("#btn_updateRole").addEventListener("click",updateRole,false);
		document.querySelector("#all").addEventListener("change",selectAll,false);
	}
	window.addEventListener("load",init,false);
})();
